import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
import Confirm from '#cpt/temp/Confirm'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {	
		data:[],
		pag: {},
		selectedKeys:[],
		selectedRows:[],
		// 搜索表单列表
		// 所有的搜索医院，项目用下拉带搜索 20211012 耿琰
		forms : [
			{ label: '姓名',			name: 'patient_name' },
			{ label: '关联条码号',	name: 'spec_code' },
			{ label: '医院名称',		name: 'hosp_id',type: 'select' },
			{ label: '种类',			name: 'status',	type: 'select',data:[{ name:'正常', value:'91,92,94,95,96,99'},{ name:'终止', value:'93' },{ name:'迟发', value:'97' },{ name:'退单', value:'98' }] },
			{ label: '打印排序',		name: 'print_sorted',	type: 'select',data:[{ name:'医院与科室升序', value:'1'},{ name:'医院与科室降序', value:'2' },{ name:'科室与医院升序', value:'3' },{ name:'科室与医院升序', value:'4' }] },
			{ label: '日期',  		names: ['start_date','end_date'], type:'date-range' },
		],
		
	}
	query = {status:''}
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
		  this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = async () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 医院
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
		})
	}
	// paging
	fetch = () => $fn.fetch.call(this,'kd-report-spec/myreportspec')
	
	// 表格
	cols = [
		{ title: '条码号',			dataIndex: 'spec_code', 		...$fn.table.spec_code },
		{ title: '送检单位', 		dataIndex: 'hosp_name', 		width:200 },
		{ title: '送检科室', 		dataIndex: 'department_name', 	width:150 },
		{ title: '送检时间', 		dataIndex: 'check_time', 		...$fn.table.time},
		{ title: '病人姓名',			dataIndex: 'patient_name', 		...$fn.table.name },
		{ title: '性别', 			dataIndex: 'contact_at', 		...$fn.table.sex,render: text => +text === 1 ? '男' : '女' },
		{ title: '年龄', 			dataIndex: 'newAge', 			...$fn.table.age},
		{ title: '报告发布时间',		dataIndex: 'created_at', 		...$fn.table.time },
		{ title: '状态', 			dataIndex: 'status_name', 		...$fn.table.status},
		TableControls.controls.call(this,{ width: 150 })
	]
	// 表格操作按钮
	table_controls = (text,{ uuid,spec_code, spec_num }) => {
		return [
			TableControls.pushTo.call(this,'预览', `preview-report?spec_num=${spec_num}&spec_code=${spec_code}`)
		]
	}
	// 操作按钮
	controls = () => {
		return [
			// 批量接收
			Confirm.call(this, '批量接收', 'kd-report-spec/uprec',{ idStr:'ids',isKeys:true } ),
			// 批量打印
			Controls.printer.call(this, { batch:true })
		]
	}
	
	render(){
		return (
			<>
				<Page title='报告单派送' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this, { isInit: window.isInit }) }
				</Page>
				
			</>
		)
	}
}

export default Index